/******************************************************************************
** 
** File name:	utest_71.c
**	
** Description:	RTOS Ver.3 Unit Tests. RTOS System Timer subsystem.
**
**				This unit test is to check RTOS Start/Test timer services.
**
** RTOS API Services to be checked:
**
**		- RTOS_StartTimerMessage()
**		- RTOS_CancelTimerMessage()
**
** Notes:	
**
*******************************************************************************
**
** Change history:
**	
** 10/09/2012 -AK- 	Test created.
**
******************************************************************************/
#include <avr/io.h>
#include <avr/interrupt.h>

#ifndef UTEST_71
#	error "UTEST_71 must be defined as -D$(Configuration) compiler option"
#endif

#include "UTEST_RES.h"

/******************************************************************************
**	UNIT TEST INTERRUPT FUNCTION[s]
******************************************************************************/

// N/A

/******************************************************************************
**	UNIT TEST TASK FUNCTIONs
******************************************************************************/
/*
** RTOS Task #0 - Stack checking task
*/
RTOS_TASK_FUNC(tsk0)
{
	while (1)
	{	
		RTOS_DebugPrint("[T0] Checking stacks consistency");
		RTOS_StackCheck(tsk0);
		RTOS_StackCheck(tsk1);
		RTOS_StackCheck(tsk2);
		RTOS_StackCheck(tsk3);
		
		RTOS_TaskSuspend(&tsk0PID);
		
	}
}

/*
** RTOS Task #1
*/
RTOS_TASK_FUNC(tsk1)
{	
	RTOS_MSG_t	*msg;

	RTOS_StartTimerMessage(&tms1, 30, &msq1);
	RTOS_StartTimerMessage(&tms2, 10, &msq1);
	RTOS_StartTimerMessage(&tms3, 20, &msq1);

	while(1)
	{
		
		msg = RTOS_WaitMessage(&msq1);

		if ( msg == &(tms1.msg) )
		{
			RTOS_StartTimerMessage(&tms1, 30, &msq1);
		}
		else if ( msg == &(tms2.msg) )
		{
			RTOS_StartTimerMessage(&tms2, 30, &msq1);
		}
		else if ( msg == &(tms3.msg) )
		{
			RTOS_StartTimerMessage(&tms3, 30, &msq1);
		}
		else
		{
			RTOS_HaltOS();
		}
		
		RTOS_TaskResume(&tsk0PID);
	}
}

/*
** RTOS Task #2 
*/
RTOS_TASK_FUNC(tsk2)
{	
	while(1)
	{		
	}
}

/*
** RTOS Task #3 
*/
RTOS_TASK_FUNC(tsk3)
{
	while(1)
	{
	}
}

